# import the necessary packages
import random

import requests

# initialize the Keras REST API endpoint URL along with the input
# image path
from Test import settings

KERAS_REST_API_URL = "http://localhost:5000/predict"
IMAGE_PATH = "dog.jpg"
# load the input image and construct the payload for the request
image = open(IMAGE_PATH, "rb").read()
payload = {"image": image}
# submit the request
index = {"index": str(random.randint(0, settings.ResNet_Layers))}
r = requests.post(KERAS_REST_API_URL, data=index, files=payload).json()
# ensure the request was sucessful
if r["success"]:
    # loop over the predictions and display them
    for (i, result) in enumerate(r["predictions"]):
        print("{}. {}: {:.4f}".format(i + 1, result["label"],
                                      result["probability"]))
# otherwise, the request failed
else:
    print("Request failed")
